package com.wetsion.securityoauthdemo.rmsclient.common;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * rms Oauth2 本地系统上下文
 * 参考自spring security 的DefaultOAuth2ClientContext
 *
 * @author weixin
 * @version 1.0
 * @CLassName RmsOauthClientContext
 * @date 2019/3/8 4:45 PM
 */
public class RmsOauthClientContext {

    private RmsOauthAccessToken rmsOauthAccessToken;

    private RmsAccessTokenRequest rmsAccessTokenRequest;

    private Map<String, Object> state = new HashMap<String, Object>();

    public RmsOauthClientContext() {
        this(new RmsAccessTokenRequest());
    }

    public RmsOauthClientContext(RmsAccessTokenRequest rmsAccessTokenRequest) {
        this.rmsAccessTokenRequest = rmsAccessTokenRequest;
    }

    public RmsOauthClientContext(RmsOauthAccessToken rmsOauthAccessToken) {
        this.rmsOauthAccessToken = rmsOauthAccessToken;
        this.rmsAccessTokenRequest = new RmsAccessTokenRequest();
    }

    public RmsOauthAccessToken getAccessToken() {
        return rmsOauthAccessToken;
    }

    public void setAccessToken(RmsOauthAccessToken accessToken) {
        this.rmsOauthAccessToken = accessToken;
        this.rmsAccessTokenRequest.setExistingToken(accessToken);
    }

    public RmsAccessTokenRequest getAccessTokenRequest() {
        return rmsAccessTokenRequest;
    }

    public void setPreservedState(String stateKey, Object preservedState) {
        state.put(stateKey, preservedState);
    }

    public Object removePreservedState(String stateKey) {
        return state.remove(stateKey);
    }
}
